<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>

<html>
<head>
	<title>角色管理</title>
	
	<script>
		$(document).ready(function() {
			//聚焦第一个输入框
			$("#role_rolename").focus();
			//为inputForm注册validate函数
			$("#inputForm").validate();
			
			//取得全选checkbox数组
			var arrChk=$("input[name='permissions_func']");
			
			//遍历数组
			$(arrChk).each(function(){
				$(this).click(function(){
					var isChecked = $(this).attr("checked");
					var permissions=$("input[id^='permission_"+ this.value +"_']"); 
					$(permissions).each(function(){
						if(isChecked)
						{
							$(this).attr("checked",isChecked);
						}
						else
						{
							$(this).removeAttr("checked");
						}
					});  
				});		
       			
    		}); 
		});
		
	</script>
</head>

<body>
<section class="content">
<div class="row">
		<div class="col-md-12">

			<!-- Primary box -->
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-edit"></i>
					<h3 class="box-title">管理角色</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">
	<form id="inputForm" action="${ctx}/role/${action}" method="post" class="form-horizontal">
		<input type="hidden" name="id" value="${role.id}"/>
		<fieldset>
			<div class="form-group">
				<label for="role_rolename" class="col-sm-3 control-label">角色名称:</label>
				<div class="col-sm-6">
					<input type="text" id="role_rolename" name="rolename"  value="${role.rolename}" class="form-control input-large required" minlength="3"/>
				</div>
			</div>	
			<div class="form-group">
				<label for="role_roleintro" class="col-sm-3 control-label">角色描述:</label>
				<div class="col-sm-6">
					<input type="text" id="role_roleintro" name="roleintro"  value="${role.roleintro}" class="form-control input-large required" minlength="3"/>
				</div>
			</div>	
			<div class="form-group">
				<label for="role_status" class="col-sm-3 control-label">状态:</label>
				<div class="col-sm-6">
					<select id="role_status" name="status" class="form-control">
						<option value="1" <c:if test="${role.status eq '1'}">selected="selected"</c:if>>有效</option>
						<option value="0" <c:if test="${role.status eq '0'}">selected="selected"</c:if>>无效</option>
					</select>
				</div>
			</div>
			<c:forEach items="${functions}" var="function">
			<div class="form-group">
				<label class="col-sm-3 control-label"><input type="checkbox" id="permissions_${function.id}" name="permissions_func"  value="${function.id}" />${function.showname}:</label>
				<div class="col-sm-6">
					<c:forEach items="${function.permissions}" var="permission">
						<input class="form-control" type="checkbox" <c:if test="${not empty role.id }">
							<c:forEach items="${permissions}" var="permission2">
								<c:if test="${permission2.id eq permission.id }">checked="checked"</c:if>
							</c:forEach>
						</c:if> id="permission_${function.id}_${permission.id}" name="permissions"  value="${permission.id}" />&nbsp;${permission.showname}&nbsp;&nbsp;
					</c:forEach>
				</div>
			</div>	
			</c:forEach>
			<!--<c:forEach items="${functions}" var="function">
			    <div class="row">
			    <div class="span3">${function.showname}</div>
			    <div class="span6">
			    	<c:forEach items="${function.permissions}" var="permission">
						<input type="checkbox" id="permission_${permission.id}" name="permissions"  value="${permission.id}" /><label>${permission.showname}:</label>
					</c:forEach>
			    </div>
			    </div>
			</c:forEach>
			--><!--<div class="form-group">
				<label for="description" class="col-sm-3 control-label">任务描述:</label>
				<div class="col-sm-6">
					<textarea id="description" name="description" class="input-large">${task.description}</textarea>
				</div>
			</div>	
			--><div class="modal-footer bg-gray">
				<input id="submit_btn" class="btn btn-primary" type="submit" value="提交"/>&nbsp;	
				<input id="cancel_btn" class="btn" type="button" value="返回" onclick="history.back()"/>
			</div>
		</fieldset>
	</form>
	</div>
	</div>
	</div>
	</div>
	</section>
</body>
</html>
